package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShopMerchant;
import com.ruoyi.system.service.IShopMerchantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/system/merchant")
public class ShopMerchantController extends BaseController
{
    @Autowired
    private IShopMerchantService shopMerchantService;

    /**
     * 查询商家信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:merchant:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopMerchant shopMerchant)
    {
        startPage();
        List<ShopMerchant> list = shopMerchantService.selectShopMerchantList(shopMerchant);
        return getDataTable(list);
    }

    /**
     * 导出商家信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:merchant:export')")
    @Log(title = "商家信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopMerchant shopMerchant)
    {
        List<ShopMerchant> list = shopMerchantService.selectShopMerchantList(shopMerchant);
        ExcelUtil<ShopMerchant> util = new ExcelUtil<ShopMerchant>(ShopMerchant.class);
        util.exportExcel(response, list, "商家信息数据");
    }

    /**
     * 获取商家信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:merchant:query')")
    @GetMapping(value = "/{merchantId}")
    public AjaxResult getInfo(@PathVariable("merchantId") Long merchantId)
    {
        return success(shopMerchantService.selectShopMerchantByMerchantId(merchantId));
    }

    /**
     * 新增商家信息
     */
    @PreAuthorize("@ss.hasPermi('system:merchant:add')")
    @Log(title = "商家信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopMerchant shopMerchant)
    {
        return toAjax(shopMerchantService.insertShopMerchant(shopMerchant));
    }

    /**
     * 修改商家信息
     */
    @PreAuthorize("@ss.hasPermi('system:merchant:edit')")
    @Log(title = "商家信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopMerchant shopMerchant)
    {
        return toAjax(shopMerchantService.updateShopMerchant(shopMerchant));
    }

    /**
     * 删除商家信息
     */
    @PreAuthorize("@ss.hasPermi('system:merchant:remove')")
    @Log(title = "商家信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{merchantIds}")
    public AjaxResult remove(@PathVariable Long[] merchantIds)
    {
        return toAjax(shopMerchantService.deleteShopMerchantByMerchantIds(merchantIds));
    }
}
